| Conditions | 1 |
| Paths | 2 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | (function () { |
||
| 10 | .directive('clearBtn', ['$parse', function ($parse) { |
||
| 11 | return { |
||
| 12 | link: function (scope, elm, attr) { |
||
| 13 | elm.wrap("<div style='position: relative'></div>"); |
||
| 14 | var btn = '<span id=' + Math.round(Math.random() * 1000000000) + ' class="searchclear ng-hide fa fa-times-circle-o"></span>'; |
||
| 15 | var angularBtn = angular.element(btn); |
||
| 16 | elm.after(angularBtn); |
||
| 17 | //clear the input |
||
| 18 | angularBtn.on("click", function () { |
||
| 19 | elm.val('').trigger("change"); |
||
| 20 | $parse(attr.ngModel).assign(scope, ''); |
||
| 21 | scope.$apply(); |
||
| 22 | }); |
||
| 23 | |||
| 24 | // show clear btn on focus |
||
| 25 | elm.bind('focus keyup change paste propertychange', function () { |
||
| 26 | if (elm.val() && elm.val().length > 0) { |
||
| 27 | angularBtn.removeClass("ng-hide"); |
||
| 28 | } else { |
||
| 29 | angularBtn.addClass("ng-hide"); |
||
| 30 | } |
||
| 31 | }); |
||
| 32 | } |
||
| 33 | }; |
||
| 34 | }]); |
||
| 35 | }()); |
||
| 38 |